<template>
  <el-dialog :close-on-click-modal="false" title="预警审核" width="900px" :visible.sync="visible">
    <el-form :model="form" label-width="110px" ref="form">
      <el-form-item label="预警规则" prop="ruleName">
        <el-input v-model="form.ruleName" :readOnly="true" />
      </el-form-item>
      <el-form-item label="上报审核意见">
        <el-input type="textarea" :rows="2" placeholder="请输入处置意见" v-model="form.reportedRemark" />
      </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button type="danger" @click="handleOk(2)">审核不通过</el-button>
      <el-button type="primary" @click="handleOk(3)">审核通过</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { warningAudit } from '@/api/prewarning'
import { openNotification } from '@/utils/util'

export default {
  data() {
    return {
      visible: false,
      form: {}
    }
  },
  methods: {
    edit(firstRow, record) {
      this.visible = true
      this.form = Object.assign({}, firstRow, record)
    },
    handleOk(handleState) {
      if (handleState === 2) {
        if (!this.form.reportedRemark) {
          this.$message.error('审核不通过时，请输入上报审核意见')
          return false
        }
      }
      this.$refs.form.validate(async valid => {
        if (valid) {
          console.log('form', this.form)
          const res = await warningAudit({ ...this.form, handleState })
          if (res.state === '000000') {
            let mes = ''
            if (handleState === 2) {
              mes = '审核不操作成功'
            } else {
              mes = '审核操作成功'
            }
            openNotification('success', mes)
            this.visible = false
            this.$emit('refresh')
          }
        }
      })
    }
  }
}
</script>
